let dd = window.dd = require('../core/index');
let SCREEN_WIDTH = 480;
let SCREEN_HEIGHT = 800;

let Imgs = window.Imgs = {};
Imgs.Img_default = 'public/default_texture.png';
Imgs.Img_battery = 'public/battery.png';

Imgs.Img_bg = 'public/bg.jpg';
Imgs.Img_leaf1 = 'public/pubs_leaf1.png';

let gameApp;
window.onload = function () {
    console.log('start....');
    let canvas = document.getElementById('game');
    gameApp = new dd.GameApp(canvas, SCREEN_WIDTH, SCREEN_HEIGHT, 2);
    dd.texCache.async_preloadImgs(Imgs).then(startGame);
};

function startGame() {
    dd.cfg.defaultTexture = dd.texCache.getTexture2D(Imgs.Img_default);
    let mapScene = new dd.Scene();

    let bg = new dd.Sprite({
        texture:dd.texCache.getTexture2D(Imgs.Img_bg),
        ax:0,
        ay:0,
        x:100,
        y:100,
    });
    mapScene.addChild(bg);

    let leaf = new dd.Sprite({
        x:400,
        y:400,
        texture: dd.texCache.getTexture2D(Imgs.Img_leaf1)
    });
    leaf.degress = 30;
    leaf.zIndex = 10;
    mapScene.addChild(leaf);
    gameApp.startWithScene(mapScene);


    let m1 = dd.moveTo(1,400,800);
    let m2 = dd.rotateTo(1,180);
    let m3 = dd.scaleTo(1,2,2);
    let seq = dd.sequence(m1,m2,m3);
    leaf.runAction(seq);

    leaf.schedule(f1,1);

    leaf.scheduleOnce(()=>{
        leaf.unschedule(f1);
        console.log(`停止掉f1!`);
    },2);
}


function f1(dt) {
    console.log(`leaf called!`,dt);
}
